package cn.com.dhc.danlu.activity.delivery.order.viewholder;

import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.math.BigDecimal;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.activity.delivery.order.bean.OrderDataBean;
import cn.com.dhc.danlu.util.CommonConst;
import cn.com.dhc.danlu.util.CommonUtils;

/**
 * author: 李一方(<a href="mailto:liyifang@danlu.com">liyifang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-02-14 15:18
 *
 * <p>
 * 订单列表 - 商品信息展示区
 * </p>
 */
public class OrderDataViewHolder extends BaseViewHolder<OrderDataBean> {
    // 商品信息
    private TextView tvGoodsName;
    // 商品原价
    private TextView tvGoodsCost;
    // 数量（商品条码后）
    private TextView tvGoodsCount;
    // 商品现价
    private TextView tvGoodsPrice;
    // 商品条码
    private TextView tvGoodsBarcode;
    // 商品图片
    private SimpleDraweeView sdvGoods;

    public OrderDataViewHolder(View itemView) {
        super(itemView);
        tvGoodsName = (TextView) itemView.findViewById(R.id.tv_name);
        tvGoodsCost = (TextView) itemView.findViewById(R.id.tv_goods_cost);
        tvGoodsCount = (TextView) itemView.findViewById(R.id.tv_goods_count);
        tvGoodsPrice = (TextView) itemView.findViewById(R.id.tv_goods_price);
        tvGoodsBarcode = (TextView) itemView.findViewById(R.id.tv_barcode);
        sdvGoods = (SimpleDraweeView) itemView.findViewById(R.id.sdv_goods);
    }

    @Override
    protected void bindViewData(OrderDataBean data) {
        // 原价
        String costPrice = data.getCostPrice();
        // 现价
        String unitPrice = data.getUnitPrice();

        sdvGoods.setImageURI(data.getPicUrl());
        tvGoodsName.setText(data.getMerchName());
        tvGoodsCost.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

        // 设置限购的价格
        if (data.getPromotionType().equals(CommonConst.PromotionConst.PROMOTION_CHANGE_TYPE_4)) {
            tvGoodsCost.setVisibility(View.VISIBLE);
            // 设置单价
            tvGoodsCost.setText(getContext().getString(R.string.rmb_unit_label).concat(CommonUtils.fenToYuan(new BigDecimal(unitPrice)).toString()));
            // 设置均价
            tvGoodsPrice.setText(getContext().getString(R.string.rmb_unit_label).concat(CommonUtils.fenToYuan(new BigDecimal(data.getAveragePrice())).toString()));
        } else if (data.getPromotionType().equals(CommonConst.PromotionConst.PROMOTION_CHANGE_TYPE_1)) {
            if (!unitPrice.equals(costPrice)) {
                tvGoodsCost.setVisibility(View.VISIBLE);
                tvGoodsCost.setText(getContext().getString(R.string.rmb_unit_label).concat(CommonUtils.fenToYuan(new BigDecimal(costPrice)).toString()));
            } else {
                tvGoodsCost.setVisibility(View.GONE);
            }
            // 设置单价
            tvGoodsPrice.setText(getContext().getString(R.string.rmb_unit_label).concat(CommonUtils.fenToYuan(new BigDecimal(unitPrice)).toString()));
        } else {
            tvGoodsCost.setVisibility(View.GONE);
            // 设置单价
            tvGoodsPrice.setText(getContext().getString(R.string.rmb_unit_label).concat(CommonUtils.fenToYuan(new BigDecimal(unitPrice)).toString()));
        }

        // 设置商品码
        tvGoodsBarcode.setText(data.getMerchBarCode());
        // 设置数量
        tvGoodsCount.setText(getContext().getString(R.string.multiple_sign_label).concat(data.getMerchCount()));
    }
}
